<template>
  <div
    class="singer_box"
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
  >
    <my-scroll>
      <div class="outter">
        <div class="inner">
          <div class="top_box ">
            <div class="img_box">
              <img :src="info.picUrl + '?param=200y200'" alt="" />
            </div>
            <div class="info_box">
              <div class="title_box">
                <div class="describe">歌手</div>
                <div class="name">{{ info.name }}</div>
              </div>
              <ul>
                <li>
                  <span class="iconfont icon-yinyue"></span>
                  <span>单曲数：{{ info.musicSize }}</span>
                </li>
                <li>
                  <span class="iconfont icon-zhuanji"></span>
                  <span>专辑数：{{ albums.length }}</span>
                </li>
                <li>
                  <span class="iconfont icon-mv1"></span>
                  <span>MV数：{{ mvs.length }}</span>
                </li>
                <!-- <li>
            <span class="iconfont icon-jita"></span>
            <span>演出数：</span>
          </li> -->
              </ul>
            </div>
            <div class="collect">
              <div>
                <span class="iconfont icon-shoucang"></span>
                <span>收藏</span>
              </div>
            </div>
          </div>
          <el-tabs class="bottom_box" v-model="tarbar">
            <el-tab-pane label="专辑" name="album">
              <div class="album" v-if="albums.length > 0">
                <div
                  v-for="(item, index) in albums"
                  :key="index"
                  class="album_item"
                >
                  <div class="album_img">
                    <img :src="item.picUrl + '?param=200y200'" alt="" />
                  </div>
                  <div class="album_name">
                    {{ item.name }}
                  </div>
                </div>
              </div>
            </el-tab-pane>
            <el-tab-pane label="热门单曲" name="single">
              <div class="single">
                <table cellspacing="0" class="el-table playlit-table" stripe>
                  <thead>
                    <th class="sort"></th>
                    <th class="opera">操作</th>
                    <th>音乐图片</th>
                    <th>音乐标题</th>
                    <th class="zj">专辑</th>
                    <th class="time">时长</th>
                  </thead>
                  <tbody>
                    <tr
                      class="el-table__row"
                      v-for="(item, index) in hotSongs"
                      :key="index"
                      @click="playMusic(item)"
                    >
                      <td
                        class="td_sort"
                        style="width:50px;textAlign:center"
                        v-html="index + 1 < 10 ? '0' + (index + 1) : index + 1"
                      ></td>
                      <td class="td_opera" style="width:70px">
                        <span class="iconfont icon-shoucang"></span>
                        <span
                          class="iconfont icon-xiazai"
                          @click="download(item)"
                        ></span>
                      </td>
                      <td>
                        <div class="img-wrap">
                          <img :src="item.al.picUrl + '?param=100y100'" alt />
                          <span class="iconfont icon-triangle-down"></span>
                        </div>
                      </td>
                      <td>
                        <div class="song-wrap">
                          <div class="name-wrap">
                            <!-- 名称 -->
                            <span>{{ item.name }}</span>
                            <!-- mv图标 -->
                            <span
                              v-if="item.mvid !== 0"
                              class="iconfont icon-mv"
                            ></span>
                          </div>
                        </div>
                      </td>
                      <td class="td_zj">{{ item.al.name }}</td>
                      <td class="td_time" style="width:80px;textAlign:center">
                        {{ item.dt | playTimeFormat }}
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </el-tab-pane>
            <el-tab-pane label="MV" name="mv">
              <div class="mvs">
                <div
                  class="item"
                  @click="toMv(item.id)"
                  v-for="(item, index) in mvs"
                  :key="index"
                >
                  <div class="img-wrap">
                    <img :src="item.imgurl + '?param=200y200'" alt />
                    <div class="num-wrap">
                      <div class="iconfont icon-shipin"></div>
                      <div class="num">{{ item.playCount | count }}</div>
                    </div>
                    <div class="iconbox">
                      <span class="iconfont icon-triangle-down"></span>
                    </div>
                  </div>
                  <div class="info-wrap">
                    <div class="name">{{ item.name }}</div>
                  </div>
                </div>
              </div>
            </el-tab-pane>

            <el-tab-pane label="歌手详情" name="info">
              <div class="desc">
                {{ desc }}
              </div>
            </el-tab-pane>
            <!-- <el-tab-pane label="相似歌手" name="similar">
        
      </el-tab-pane> -->
          </el-tabs>
        </div>
      </div>
    </my-scroll>
  </div>
</template>
<script>
import request from "../../api/request"
export default {
  name: "singer",
  data() {
    return {
      loading: true,
      tarbar: "album",
      type: 1,
      page: 1,
      songs: [],
      lists: [],
      id: null,
      img: null,
      desc: null,
      info: {
        picUrl: "",
        name: "",
      },
      albums: [],
      hotSongs: [],
      mvs: [],
    }
  },
  created() {
    this.id = this.$route.query.id
    this.getSingerInfo()
    this.getAlbum()
    this.getSingle()
    this.getSingerMv()
    // this.getSimilarSinger()
  },
  methods: {
    // 点击播放歌曲
    async playMusic(item) {
      this.$store.dispatch("getSong", { id: item.id, autoplay: true })
    },
    //   歌手详情
    async getSingerInfo() {
      let res = await request({
        url: "/artist/desc",
        data: {
          id: this.id,
        },
        method: "get",
      })
      this.desc = res.briefDesc
      if (this.desc) {
        this.loading = false
      }
    },
    // 获取歌手专辑
    async getAlbum() {
      let res = await request({
        url: "/artist/album",
        data: {
          id: this.id,
        },
        method: "get",
      })
      this.info = res.artist
      this.albums = res.hotAlbums
    },
    // 获取专辑详情
    async getAlbumInfo(id) {
      let res = await request({
        url: "/album",
        data: {
          id,
        },
        method: "get",
      })
    },
    // 获取歌手单曲
    async getSingle() {
      let res = await request({
        url: "/artists",
        data: {
          id: this.id,
        },
        method: "get",
      })
      this.hotSongs = res.hotSongs
    },
    // 获取歌手MV
    async getSingerMv() {
      let res = await request({
        url: "/artist/mv",
        data: {
          id: this.id,
        },
        method: "get",
      })
      this.mvs = res.mvs
    },
    // 获取相似歌手
    async getSimilarSinger() {
      let res = await request({
        url: "/simi/artist",
        data: {
          id: this.id,
        },
        method: "get",
      })
      //   this.similar = res.mvs
      console.log(res)
    },
    toMv(id) {
      this.$router.push(`/details?id=${id}`)
    },
    // 下载按钮
    async download(item) {
      let res = await request({
        url: "/song/url",
        data: {
          id: item.id,
        },
        method: "get",
      })
      if (res.data[0].url) {
        let url = res.data[0].url
        console.log(url)
        let link = document.createElement("a")
        link.style.display = "none"
        link.href = url
        link.target = "_Blank"
        link.setAttribute("download", "测试excel.xls")
        document.body.appendChild(link)
        link.click()
      } else {
        this.$notify.error({
          title: "错误",
          message: `歌曲 ${item.name} 是vip歌曲无法获取`,
        })
      }
    },
  },
}
</script>
<style lang="scss" scoped>
@import "../../scss/common.scss";
.singer_box {
  width: 100%;
  height: 100%;
  .outter {
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    .inner {
      width: 100%;
      max-width: 1200px;
      padding: 20px;
      box-sizing: border-box;
    }
  }
  .top_box {
    display: flex;
    margin-bottom: 20px;
    .img_box {
      width: 200px;
      height: 200px;
      box-sizing: border-box;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
    .info_box {
      width: calc(100% - 300px);
      padding-left: 20px;
      box-sizing: border-box;
      text-align: left;
      .title_box {
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        .describe {
          height: 18px;
          width: 40px;
          font-size: 13px;
          line-height: 18px;
          text-align: center;
          color: white;
          background: $primary;
          border: 1px solid $primary;
          margin-right: 10px;
        }
        .name {
          font-size: 25px;
          font-weight: bold;
        }
      }
      ul {
        li {
          list-style: none;
          height: 30px;
          line-height: 30px;
          span {
            text-align: left;
            font-size: 14px;
            color: rgb(75, 74, 74);
          }
          .iconfont {
            font-size: 16px;
          }
          .icon-jita {
            color: black;
          }
        }
      }
    }
    .collect {
      width: 100px;
      display: flex;
      justify-content: flex-end;
      div {
        text-align: center;
        width: 70px;
        height: 25px;
        line-height: 25px;
        border-radius: 4px;
        border: 1px solid #ccc;
        span {
          font-size: 13px;
        }
        transition: 0.5s;
      }
      div:hover {
        cursor: pointer;
        color: $primary;
        border-color: $primary;
      }
    }
  }
  .bottom_box {
    .album {
      display: flex;
      flex-wrap: wrap;
      .album_item {
        width: 16.66%;
        padding: 10px;
        box-sizing: border-box;
        margin-bottom: 10px;
        .album_img {
          width: 100%;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
      }
      .album_name {
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        overflow: hidden; //超出的文本隐藏
        text-overflow: ellipsis; //溢出用省略号显示
        white-space: nowrap; //溢出不换行
      }
    }
    .single {
      .img-wrap {
        width: 40px;
        height: 40px;
        margin-right: 30px;
        overflow: hidden;
        position: relative;
        img {
          width: 100%;
          height: 100%;
        }
        .icon-triangle-down {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          width: 25px;
          height: 25px;
          color: $primary;
          font-size: 12px;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          background: rgba(255, 255, 255, 0.8);
          opacity: 1;
          transition: 0.5s;
          display: none;
        }

        tr:hover .icon-triangle-down {
          opacity: 1;
        }
      }
      td {
        border: none;
        .iconfont {
          padding: 0px 2px;
          transition: 0.5s;
        }
        .icon-xiazai {
          font-size: 18px;
        }
        .iconfont:hover {
          color: $primary;
        }
      }
      tr {
        padding: 0px 10px;
        box-sizing: border-box;
      }
      tr:hover {
        cursor: pointer;
        background: rgb(236, 236, 236);
      }
      .icon-triangle-down::before {
        transform: translateX(1px);
      }
    }
    .mvs {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      .item {
        width: 20%;
        cursor: pointer;
        box-sizing: border-box;
        padding: 10px;
        .img-wrap {
          width: 100%;
          position: relative;
          .iconbox {
            position: absolute;
            top: 0px;
            left: 0px;
            width: 100%;
            height: 100%;
            color: rgb(98, 158, 218);
            display: flex;
            justify-content: center;
            align-items: center;
            opacity: 0;
            transition: 0.5s;
            span {
              color: $primary;
              width: 35px;
              height: 35px;
              background: rgba(255, 255, 255, 0.7);
              display: flex;
              justify-content: center;
              align-items: center;
              border-radius: 50%;
            }
            span:hover {
              cursor: pointer;
            }
            span:before {
              transform: translateX(1px);
            }
          }
          img {
            width: 100%;
            object-fit: cover;
            border-radius: 5px;
          }
          .num-wrap {
            position: absolute;
            color: white;
            top: 0;
            right: 0;
            left: 0;
            display: flex;
            height: 20px;
            line-height: 20px;
            background: rgba(0, 0, 0, 0.2);
            align-content: center;
            font-size: 15px;
            padding-right: 5px;
            padding-top: 2px;
            display: flex;
            justify-content: flex-end;
            .icon-shipin {
              padding-right: 5px;
            }
            .icon-triangle-down {
              font-size: 12px;
              display: flex;
              align-items: center;
              margin-right: 5px;
            }
          }
        }
        .img-wrap:hover .iconbox {
          opacity: 1;
        }
        .info-wrap {
          .name {
            font-size: 15px;
            height: 25px;
            line-height: 25px;
            font-size: 15px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }
    .desc {
      text-align: left;
      font-size: 14px;
      line-height: 20px;
    }
  }
}

/deep/ .el-tabs__item.is-active {
  color: $primary;
}
/deep/ .el-tabs__active-bar {
  background-color: $primary;
}
/deep/ .el-tabs__nav div:hover {
  color: $primary;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: $primary;
}
/deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: $primary;
}
/deep/ .el-loading-spinner i {
  color: $primary !important;
}
/deep/ .el-loading-text {
  color: $primary !important;
}
@media (max-width: 600px) {
  .singer_box {
    .outter {
      .inner {
        padding-bottom: 60px;
        box-sizing: border-box;
      }
    }
    .top_box {
      .img_box {
        width: 9.375rem;
        height: 9.375rem;
        box-sizing: border-box;
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
      .info_box {
        width: calc(100% - 9.375rem);
        padding-left: 20px;
        box-sizing: border-box;
        text-align: left;
        .title_box {
          display: flex;
          align-items: center;
          margin-bottom: 10px;
          .describe {
            height: 18px;
            width: 40px;
            font-size: 13px;
            line-height: 18px;
            text-align: center;
            color: white;
            background: $primary;
            border: 1px solid $primary;
            margin-right: 10px;
          }
          .name {
            font-size: 1.25rem;
            font-weight: bold;
            word-wrap: break-word;
            word-break: normal;
          }
        }
        ul {
          li {
            list-style: none;
            height: 30px;
            line-height: 30px;
            span {
              text-align: left;
              font-size: 0.8125rem;
              color: rgb(75, 74, 74);
            }
            .iconfont {
              font-size: 0.9375rem;
              padding-right: 0.3125rem;
            }
            .icon-jita {
              color: black;
            }
          }
        }
      }
      .collect {
        display: none;
      }
    }
    .bottom_box {
      padding-bottom: 20px;
      box-sizing: border-box;
      .album {
        .album_item {
          width: 50%;
        }
      }
      .single {
        .sort {
          display: none;
        }
        .opera {
          display: none;
        }
        .zj {
          display: none;
        }
        .td_sort {
          display: none;
        }
        .td_zj {
          display: none;
        }
        .td_opera {
          display: none;
        }
      }
      .mvs {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        padding-bottom: 20px;
        box-sizing: border-box;
        .item {
          width: 50%;
        }
      }
      .desc {
        text-align: left;
        font-size: 14px;
        line-height: 20px;
        padding-bottom: 20px;
        box-sizing: border-box;
      }
    }
  }
}
</style>
